//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package org.mybatis.generator.api.dom.java;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import org.mybatis.generator.api.dom.OutputUtilities;
import org.mybatis.generator.internal.util.StringUtility;

public class Interface extends JavaElement implements CompilationUnit {
    private Set<FullyQualifiedJavaType> importedTypes;
    private Set<String> staticImports;
    private FullyQualifiedJavaType type;
    private Set<FullyQualifiedJavaType> superInterfaceTypes;
    private List<Method> methods;
    private List<String> fileCommentLines;

    public Interface(FullyQualifiedJavaType type) {
        this.type = type;
        this.superInterfaceTypes = new LinkedHashSet();
        this.methods = new ArrayList();
        this.importedTypes = new TreeSet();
        this.fileCommentLines = new ArrayList();
        this.staticImports = new TreeSet();
    }

    public Interface(String type) {
        this(new FullyQualifiedJavaType(type));
    }

    public Set<FullyQualifiedJavaType> getImportedTypes() {
        return Collections.unmodifiableSet(this.importedTypes);
    }

    public void addImportedType(FullyQualifiedJavaType importedType) {
        if (importedType.isExplicitlyImported() && !importedType.getPackageName().equals(this.type.getPackageName())) {
            this.importedTypes.add(importedType);
        }

    }

    public String getFormattedContent() {
        StringBuilder sb = new StringBuilder();
        Iterator var2 = this.fileCommentLines.iterator();

        String staticImport;
        while(var2.hasNext()) {
            staticImport = (String)var2.next();
            sb.append(staticImport);
            OutputUtilities.newLine(sb);
        }

        if (StringUtility.stringHasValue(this.getType().getPackageName())) {
            sb.append("package ");
            sb.append(this.getType().getPackageName());
            sb.append(';');
            OutputUtilities.newLine(sb);
            OutputUtilities.newLine(sb);
        }

        var2 = this.staticImports.iterator();

        while(var2.hasNext()) {
            staticImport = (String)var2.next();
            sb.append("import static ");
            sb.append(staticImport);
            sb.append(';');
            OutputUtilities.newLine(sb);
        }

        if (this.staticImports.size() > 0) {
            OutputUtilities.newLine(sb);
        }

        Set<String> importStrings = OutputUtilities.calculateImports(this.importedTypes);
        Iterator var8 = importStrings.iterator();

        while(var8.hasNext()) {
            String importString = (String)var8.next();
            sb.append(importString);
            OutputUtilities.newLine(sb);
        }

        if (importStrings.size() > 0) {
            OutputUtilities.newLine(sb);
        }

        int indentLevel = 0;
        this.addFormattedJavadoc(sb, indentLevel);
        this.addFormattedAnnotations(sb, indentLevel);
        sb.append(this.getVisibility().getValue());
        if (this.isStatic()) {
            sb.append("static ");
        }

        if (this.isFinal()) {
            sb.append("final ");
        }

        sb.append("interface ");
        sb.append(this.getType().getShortName());
        if (this.getSuperInterfaceTypes().size() > 0) {
            sb.append(" extends ");
            boolean comma = false;

            FullyQualifiedJavaType fqjt;
            for(Iterator var5 = this.getSuperInterfaceTypes().iterator(); var5.hasNext(); sb.append(JavaDomUtils.calculateTypeName(this, fqjt))) {
                fqjt = (FullyQualifiedJavaType)var5.next();
                if (comma) {
                    sb.append(", ");
                } else {
                    comma = true;
                }
            }
        }

        sb.append(" {");
        indentLevel = indentLevel + 1;
        Iterator mtdIter = this.getMethods().iterator();

        while(mtdIter.hasNext()) {
            OutputUtilities.newLine(sb);
            Method method = (Method)mtdIter.next();
            sb.append(method.getFormattedContent(indentLevel, true, this));
            if (mtdIter.hasNext()) {
                OutputUtilities.newLine(sb);
            }
        }

        --indentLevel;
        OutputUtilities.newLine(sb);
        OutputUtilities.javaIndent(sb, indentLevel);
        sb.append('}');
        return sb.toString();
    }

    public void addSuperInterface(FullyQualifiedJavaType superInterface) {
        this.superInterfaceTypes.add(superInterface);
    }

    public List<Method> getMethods() {
        return this.methods;
    }

    public void addMethod(Method method) {
        this.methods.add(method);
    }

    public FullyQualifiedJavaType getType() {
        return this.type;
    }

    public FullyQualifiedJavaType getSuperClass() {
        return null;
    }

    public Set<FullyQualifiedJavaType> getSuperInterfaceTypes() {
        return this.superInterfaceTypes;
    }

    public boolean isJavaInterface() {
        return true;
    }

    public boolean isJavaEnumeration() {
        return false;
    }

    public void addFileCommentLine(String commentLine) {
        this.fileCommentLines.add(commentLine);
    }

    public List<String> getFileCommentLines() {
        return this.fileCommentLines;
    }

    public void addImportedTypes(Set<FullyQualifiedJavaType> importedTypes) {
        this.importedTypes.addAll(importedTypes);
    }

    public Set<String> getStaticImports() {
        return this.staticImports;
    }

    public void addStaticImport(String staticImport) {
        this.staticImports.add(staticImport);
    }

    public void addStaticImports(Set<String> staticImports) {
        this.staticImports.addAll(staticImports);
    }
}
